package com.spring.boot.rabbit.configure.rabbit;

import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.spring.boot.rabbit.constant.ExchangeConst.DIRECT_EXCHANGE;
import static com.spring.boot.rabbit.constant.ExchangeConst.TOPIC_EXCHANGE;


/**
 * RabbitMQ-交换机配置类
 *
 * @author 李坤
 * @date 2022/9/1 11:21
 */
@Configuration
public class ExchangeConfigure {

    /**
     * 创建 direct 类型消息交换机
     * <p>
     * routing-key类型为: a.# > a.b.# > a.b.c.#
     *
     * @return 消息交换机
     */
    @Bean
    public Exchange topicExchange() {
        return ExchangeBuilder.topicExchange(TOPIC_EXCHANGE).durable(false).build();
    }

    /**
     * 创建 direct 类型消息交换机
     * <p>
     * routing-key类型为: x、y、z
     *
     * @return 消息交换机
     */
    @Bean
    public Exchange directExchange() {
        return ExchangeBuilder.directExchange(DIRECT_EXCHANGE).durable(false).build();
    }

}
